package com.hulk.dryad.web.shedlock;


import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @Author: hulk
 * @E-mail: 29572320@qq.com
 * @Date: Create in 2019-05-18 22:37
 * @Version: 1.0.0
 * @Modify by:
 * Class description
 */
@Slf4j
@Component
public class DataHouseKeepingScheduler {


	@Resource
	private DynamicRoutingDataSource ds;

    @Scheduled(cron = "*/59 * * * * ?")
    @SchedulerLock(name = "dataHouseKeepingLock", lockAtLeastFor = "PT30S", lockAtMostFor = "PT30M")
    public void dataHouseKeeping(){
		ds.getCurrentDataSources().keySet().forEach(v->{
			log.info("DateSource key:[{}]",v);
		});
        log.info(String.format("[%s] DataHouseKeeping job run...", LocalDateTime.now()));
    }
    @Scheduled(cron = "*/59 * * * * ?")
    @SchedulerLock(name = "dataHouseKeepingLock", lockAtLeastFor = "PT30S", lockAtMostFor = "PT30M")
    public void dataHouseKeeping1(){
		ds.getCurrentDataSources().keySet().forEach(v->{
			log.info("DateSource key:[{}]",v);
		});
        log.info(String.format("[%s] DataHouseKeeping1 job run...", LocalDateTime.now()));
    }
}